package com.jsgt.greekfire.ui.mine.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.fhx.core.utils.PriceFormatUtil
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.AssetsBean

class MineAdapter : BaseAdapter<AssetsBean>() {

    var gfcPrice: Int = 0
    var usdtPrice: Int = 0

    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var icon_tv: ImageView? = null
        var coin_name_tv: TextView? = null
        var dollar_tv: TextView? = null
        var dollar_bb: TextView? = null

        init {
            icon_tv = itemView.findViewById(R.id.icon_tv)
            coin_name_tv = itemView.findViewById(R.id.coin_name_tv)
            dollar_tv = itemView.findViewById(R.id.dollar_tv)
            dollar_bb = itemView.findViewById(R.id.dollar_bb)
        }

        fun bindData(bean: AssetsBean) {
            var sum = ""


            coin_name_tv?.text = bean.assetName
            when (bean.assetGuid) {
                "1" -> {
                    sum = PriceFormatUtil.format(
                        (bean.assetBalance!! + bean.assetFrozen!!) * gfcPrice,
                        4
                    )
                    icon_tv?.setImageResource(R.mipmap.icon_glb)
                }
                "2" -> {
                    sum = PriceFormatUtil.format(
                        (bean.assetBalance!! + bean.assetFrozen!!) * usdtPrice,
                        4
                    )
                    icon_tv?.setImageResource(R.mipmap.icon_usdt)
                }

                "3" -> {
                    sum = PriceFormatUtil.format(
                        (bean.assetBalance!! + bean.assetFrozen!!) * gfcPrice,
                        4
                    )
                    icon_tv?.setImageResource(R.mipmap.icon_gft)
                }

//                "4"->{
//                    sum = PriceFormatUtil.format((bean.assetBalance!!+bean.assetFrozen!!) * MONEY_UTIT_SCALE * MONEY_SCALE, 4)
//                    icon_tv?.setImageResource(R.mipmap.icon_ut)
//                }
            }
            dollar_bb?.text = "$  " + PriceFormatUtil.format((bean.assetBalance!! + bean.assetFrozen!!), 4)
            dollar_tv?.text = sum.toString()
        }
    }

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_mine, parent, false)
        return VH(view)
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }

}